package com.oauth.google.client.ui.picasa;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.google.client.beans.picassa.GooglePicasaAlbum;

public class AlbumList extends Composite {

	private static AlbumListUiBinder uiBinder = GWT.create(AlbumListUiBinder.class);

	interface AlbumListUiBinder extends UiBinder<Widget, AlbumList> {
	}

	@UiField
	ListBox listBox;

	public AlbumList() {
		initWidget(uiBinder.createAndBindUi(this));

	}

	public void addAlbums(List<GooglePicasaAlbum> pList) {
		listBox.clear();
		listBox.setVisibleItemCount(20);
		for (GooglePicasaAlbum album : pList) {
			listBox.addItem(album.getTitle(), album.getAlbumId());
		}
		listBox.addChangeHandler(new ChangeHandler() {

			@Override
			public void onChange(ChangeEvent pEvent) {
				// TODO Auto-generated method stub
				ListBox listBox = (ListBox) pEvent.getSource();
				listBox.getValue(listBox.getSelectedIndex());
			}
		});
	}

}
